package com.cheneyjoo.util;

import com.cheneyjoo.view.Index;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

public class ClientInit {
    private Socket socket;
    /**
     * 开启客户端
     *
     * @throws IOException
     */
    public void start() throws IOException {
        socket = new Socket(InetAddress.getLocalHost(), 8888);
        System.out.println("连接服务器成功");
        new Index(socket).index();
        //in=new BufferedReader(new InputStreamReader(socket.getInputStream()));
//        ClientThread ct=new ClientThread(socket);
//        Thread thread=new Thread(ct);
//        thread.start();
//        out=new PrintStream(socket.getOutputStream());
//        while (true){
//            System.out.println("请输入：");
//            String readLine = CheneyScanner.reader.readLine();
//            out.println(readLine);
//            if ("bye".equalsIgnoreCase(readLine))
//            {
//                break;
//            }
//        }
        close();
    }

    /**
     * 关闭客户端
     *
     * @throws IOException
     */
    public void close() throws IOException {
        socket.close();
    }
}
